package com.gaofans.nrpc.client.bootstrap;

import com.gaofans.nrpc.client.handler.ClientFilter;
import com.gaofans.nrpc.client.handler.ResponseEventProcessor;
import com.gaofans.nrpc.client.route.Router;
import com.gaofans.nrpc.common.context.SelectableExecutor;
import com.gaofans.nrpc.common.id.IdGenerator;
import com.gaofans.nrpc.common.processor.ServiceAuthority;
import io.netty.channel.Channel;

import java.net.URI;

/**
 * @author GaoFans
 */
public interface ChannelManager extends AutoCloseable{

    /**
     * 连接
     * @param info
     * @return
     */
    Channel connect(ServiceAuthority info);

    /**
     * 连接
     * @param uri
     * @return
     */
    Channel connect(URI uri);

    /**
     * 获取一个连接
     * @param info
     * @return
     */
    Channel get(ServiceAuthority info);

    /**
     * 获取一个连接
     * @param uri
     * @return
     */
    Channel get(URI uri);

    /**
     * 关闭指定连接
     * @param info
     * @return
     */
    void close(ServiceAuthority info);

    /**
     * 获取 processor
     * @return
     */
    ResponseEventProcessor processor();

    /**
     * 获取 ExecutorChooser
     * @return
     */
    SelectableExecutor chooser();

    /**
     * 注册router
     * @param router
     */
    void register(Router router);

    /**
     * 添加过滤器
     * @param filter
     */
    void addFilter(ClientFilter filter);

    /**
     * 获取id生成器
     * @return
     */
    IdGenerator idGenerator();

}
